package sxh.springMvc;



import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import sxh.mybatis.dao.User;
import sxh.mybatis.dao.UserMapper;


@Controller
public class testSpring {
	@Autowired
	private druidUtil du;
	@Autowired
	private UserMapper usermapper;
	@RequestMapping(value = "sayhello")
	public ModelAndView sayHello() {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("pages/love");
		System.out.println("你好");
		modelAndView.addObject("love", "(*^__^*) 嘻嘻……");
		return modelAndView;
	}

	@RequestMapping(value = "testdruid")
	public ModelAndView testDruid() {
		ModelAndView modelAndView = new ModelAndView();
		System.out.println("test--------------druid");
		modelAndView.setViewName("pages/love");
		modelAndView.addObject("love", "test--------------druid");
		du.getdata();
		return modelAndView;
	}
	
/*	1、 在mapper.xml中将namespace设置为mapper.Java的全限定名 
	2、 将mapper.java接口的方法名和mapper.xml中statement的id保持一致。 
	3、 将mapper.java接口的方法输入参数类型和mapper.xml中statement的parameterType保持一致 
	4、 将mapper.java接口的方法输出 结果类型和mapper.xml中statement的resultType保持一致
	
	参数的传递方式有三种：
	1、bean实体类，属性名称和字段名称一致
	2、map key名称和#{key}
	3、#{0}、#{1}按照参数的索引来入参
	4、参数为字符串可以直接用名称
	5、$的使用需要先命名
	*/ 
	@RequestMapping(value = "testmybatis1")
	public ModelAndView testmybatis1() {
		ModelAndView modelAndView = new ModelAndView();
		User user=new User(1,"10","晓虎");
		usermapper.save(user);
		return modelAndView;
	}
	@RequestMapping(value = "testmybatis")
	public ModelAndView testmybatis() {
		ModelAndView modelAndView = new ModelAndView();
		String sql="select user_id id,user_name userName,user_age age from t_user";
		usermapper.useSqlString(sql);
		
		return modelAndView;
	}
}
